class Solution(object):
    def areSentencesSimilar(self, sentence1, sentence2):
        s1 = sentence1.split(' ')
        s2 = sentence2.split(' ')
        if len(s1) > len(s2):
            s1, s2 = s2, s1
        n1 = len(s1)
        n2 = len(s2)
        left1 = 0
        left2 = 0
        while left1 < n1 and s1[left1] == s2[left2]:
            left1 += 1
            left2 += 1
        right1 = n1 - 1
        right2 = n2 - 1
        while right1 >= 0 and s1[right1] == s2[right2]:
            right1 -= 1
            right2 -= 1
        return left1 > right1
